/*******************************************************************************
*
*   Copyright ©2009 Alexandru Marin
*
*   This file is part of nwave/pMRI C library.
*
*   This project started as an MSc degree project during a
*   stage at the Paris-Est university, under joint supervision of prof.
*   Bogdan Ionescu (Image Analysis and Processing Laboratory, "Politehica"
*   University of Bucharest), Caroline Chaux and Jean-Christophe Pesquet
*   (Laboratoire d'Informatique, Université Paris-Est, Institut Gaspard Monge).
*
*   nwave/pMRI C libray is free software: you can redistribute it and/or modify
*   it under the terms of the GNU General Public License as published by
*   the Free Software Foundation, either version 2 of the License, or
*   (at your option) any later version.
*
*   nwave/pMRI C libray is distributed in the hope that it will be useful,
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*   GNU General Public License for more details.
*
*   You should have received a copy of the GNU General Public License
*   along with nwave/pMRI C library.  If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/

#include "mri_types.h"
#include "mri_utils.h"
#include "dwt_core.h"
#include "dwt_types.h"
#include "dwt_utils.h"

int main() {

	FILE* f;
	float* data;

	printf("Reading the image...\n");
	f = fopen("testimage.csv","r");
	mri_matrix_descriptor_t desc;
	data = mri_read_real_matrix(f, &desc);
	fclose(f);

	printf("Reading the DWT filter(s)...\n");
	dwt_filter_set_path("../Release/filters/");
	dwt_filter_t* filter_db2 = dwt_filter_load("db2");
	dwt_filter_t* filter_haar = dwt_filter_load("haar");

	printf("Creating DWT parameters object...\n");
	dwt_params_t* params = dwt_params_alloc(2);

	params->filters[0] = filter_db2;
	params->border_strategies[0] = BORDER_PERIOD;
	params->res_levels[0] = 2;

	params->filters[1] = filter_haar;
	params->border_strategies[1] = BORDER_PERIOD;
	params->res_levels[1] = 3;

	printf("Applying DWT on the data with following parameters...\n");
	dwt_params_write(stdout,params);
	dwt_real_decomposition(data, &desc, params);

	printf("Writing transformed image...\n");
	f = fopen("testimage_transf.csv","w");
	mri_write_real_matrix(f, data, &desc);
	fclose(f);

	printf("Applying IDWT on the data...\n");
	dwt_real_reconstruction(data, &desc, params);

	printf("Writing reconstructed image...\n");
	f = fopen("testimage_rec.csv","w");
	mri_write_real_matrix(f, data, &desc);
	fclose(f);

	// Some cleanup
	dwt_params_free(params);

	return 0;
}
